<?php

namespace App\Http\Controllers\common;

use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use \Exception;
use Mail;

class EmailController extends Controller
{
    /**
    * 发送电子邮件
    *  @param string or array $email['user'] 给谁发送的邮件
    *  @param string $email['title'] 发送的邮件标题
    *  @param array $user 模板数据    //和模板内容有关 
    *           path: views\common\email\msgwarning 
    *              string $user['area'] 拼接的位置
    *              string $user['num'] 设备编号
    *              string $user['content'] 告警信息
    */
    public function sendEmail($email,$user,$ModelPash='') {
        if(empty($ModelPash)){
            $ModelPash = 'common.email.msgwarning';
        }
        try{
            $bool = Mail::send($ModelPash,['user'=>$user],function ($m) use ($email) {
                $m->to($email['user'])->subject($email['title']);    
            });
            return $bool;
        } catch(Exception $e) {
            return false;
        }
    }
}
